package lunsfordhall.androidapp;

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;

public class Form3 extends Activity {
//PE=1/2kx^2
	public void onCreate(Bundle savedInstanceState) {// bundles all of work and saves
        super.onCreate(savedInstanceState);
        
        setContentView(R.layout.form3);
        
        
        final EditText edittext = (EditText) findViewById(R.id.edittext);// enter text box for distance
        final EditText edittext2 = (EditText) findViewById(R.id.edittext2);// enter text box for velocity intital
        final EditText edittext3 = (EditText) findViewById(R.id.edittext3);// enter 
        final Button button = (Button) findViewById(R.id.button1);//makes button
        
        button.setOnClickListener(new OnClickListener() {//reads button action
        	public void onClick(View v) {// when click happens this ensues
        		
        		 TextView t = (TextView)findViewById(R.id.textview);// the variable for the output of answer
        		
        		double PE = Double.parseDouble(edittext.getText().toString());//parsing the double variables
             	
             	double k = Double.parseDouble(edittext2.getText().toString());//parsing the double variables
             	
             	double x = Double.parseDouble(edittext3.getText().toString());//parsing the double variables
             	
             		double potential_energy = 0;
             	    double distance = 0;
             	    double k_ = 0;
             	   if(k>0 && x>0 && PE==0){
                   	potential_energy =(k*Math.pow(x,2))/2;
                   t.setText(String.valueOf(potential_energy));
                    }else if(PE>0 && x>0 && k==0){
                   k_ = (PE*2/Math.pow(x, 2));
                   t.setText(String.valueOf(k_));
                    }else if(PE>0 && k>0 &&x==0){
                   double temp=(2*PE/k);
                   distance = Math.sqrt(temp);	
                   t.setText(String.valueOf(distance));
                   }else{ }
	
}
});
}
}
